<?php

namespace App\Observers\Train;

use App\Models\Train\TrainSeatInfo\TrainSeatInfo;
use Illuminate\Support\Facades\Cache;
use function config;

class TrainSeatInfoObserver
{
    /**
     * Handle the User "created" event.
     *
     * @param TrainSeatInfo $seat_info
     *
     * @return void
     */
    public function created(TrainSeatInfo $seat_info)
    {
        $cache_key = "Train:SeatInfo:{$seat_info->train_code}:{$seat_info->from_code}:{$seat_info->to_code}:{$seat_info->seat_name}:{$seat_info->name}";
        Cache::put($cache_key, $seat_info->refresh(), 5 * config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param TrainSeatInfo $seat_info
     *
     * @return void
     */
    public function updated(TrainSeatInfo $seat_info)
    {
        $cache_key = "Train:SeatInfo:{$seat_info->train_code}:{$seat_info->from_code}:{$seat_info->to_code}:{$seat_info->seat_name}:{$seat_info->name}";
        Cache::put($cache_key, $seat_info->refresh(), 5 * config('trip.ttl.day'));
    }

    public function saved(TrainSeatInfo $seat_info)
    {
        $cache_key = "Train:SeatInfo:{$seat_info->train_code}:{$seat_info->from_code}:{$seat_info->to_code}:{$seat_info->seat_name}:{$seat_info->name}";
        Cache::put($cache_key, $seat_info->refresh(), 5 * config('trip.ttl.day'));
    }
}
